package com.imooc;

import com.imooc.controller.WelcomeController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.*;
import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
import org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.Resource;
import org.w3c.dom.Element;

import java.util.Set;

/**
 * <h1>BeanDefinitionReader</h1>
 * 	作用:

 * 	1. 读取BeanDefinition <br/>
 * 	2. BeanDefinitionRegistry
 *
 * {@link BeanDefinitionReader}
 * 	{@link AbstractBeanDefinitionReader#loadBeanDefinitions(String, Set)}
 * 	里面  的{@link BeanDefinitionReader#loadBeanDefinitions(Resource)} 使用模板方法和策略模式,  由特定方向子类进行实现
 * 	参看 <br />
 * 	@see XmlBeanDefinitionReader
 * @see PropertiesBeanDefinitionReader 这个是properties文件配置, 用的比较少
 *
 *
 *  {@link DefaultBeanDefinitionDocumentReader#doRegisterBeanDefinitions(org.w3c.dom.Element)}
 *
 *  {@link DefaultBeanDefinitionDocumentReader#processBeanDefinition}
 *  {@link BeanDefinitionParserDelegate#parseBeanDefinitionElement(Element, String, BeanDefinition)}
 *  {@link BeanDefinitionReaderUtils#registerBeanDefinition(BeanDefinitionHolder, BeanDefinitionRegistry)}
 *  实际注册BeanDefinitionregisterBeanDefinition
 *  {@link DefaultListableBeanFactory#registerBeanDefinition}
 *
 *
 *  #############6.9 {@link BeanDefinitionRegistry}
 *  		{@link BeanDefinitionReader}

 *
 * @author : dzj
 * @create: 2021-10-16 19:36
 */
@Slf4j
@Configuration
@ComponentScan("com.imooc")
public class Debug0607 {

	public static void main(String[] args) {
		String xmlPath = "F:\\ideaProjectSource\\spring-framework-5.1.x\\spring-demo\\src\\main\\resources\\spring\\spring-config.xml";
		ApplicationContext ctx = new FileSystemXmlApplicationContext(xmlPath);
		//	ApplicationContext ctx = new AnnotationConfigApplicationContext(Debug0607.class);
		WelcomeController welcomeController = ctx.getBean(WelcomeController.class);
		welcomeController.handleRequest();
		for (String beanDefinitionName : ctx.getBeanDefinitionNames()) {
		//	log.info();
	//		log.info("beanDefinitionName: {}",beanDefinitionName);
		}

	}
}
